angular.module("driver").controller("AroundCtrl", ['$scope', '$meteor',
  '$rootScope', '$state', '$ionicPopup', 'Map',
  function($scope, $meteor, $rootScope, $state, $ionicPopup, Map) {

  	$scope.request = function () {
      console.log(Meteor.user());
      if (!Meteor.user()) {
            //throw new Meteor.Error("未登录！", "必须先登录！");           
        var alertPopup = $ionicPopup.alert({
          title: '温馨提示',
          template: '请您先登录！',
          okType: 'button-royal',
          okText: '确定'
        });
        alertPopup.then(function(res) {
          $state.go('account');
        });
        return false;
      }
      else {
        $state.go('order');
      }

      $meteor.call('addRequest').then(
        function (data) {
          $meteor.call('setRequest', Meteor.userId(), true);
          //成功发送申请，不做处理，页面上面自动有派发订单的提示。
          //console.log('data = ', data);
        },
        function (err) {
          var alertPopup = $ionicPopup.alert({
            title: err.error,
            template: '<i>' + err.reason + '</i>',
            okType: 'button-royal',
            okText: '确定'
          });
        }
      );
    };
    
  }
]);